﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil.CustomObject;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Name
{   
    [Serializable]
    [VerfityAttribute(Id = "VerfityN0100", Name = "姓名结果为特定项目时抽出", CategoryType = EnumCategoryType.姓名, Model = true)]
    public class VerfityN0100 : VerfityOneResult
    {
        private CustomCollection<StringArray> _datalist = new CustomCollection<StringArray>() { Description = "指定数据列表" };

        public bool InDataList { get; set; }

        [Category("指定数据列表"), Description("输入指定数据项目")]
        [TypeConverter(typeof(CustomCollectionConverter<StringArray>))]
        [RefreshProperties(RefreshProperties.All)]
        public CustomCollection<StringArray> DataList
        {
            get { return _datalist; }
            //set { _rangelist = value; }
        }

        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (entryCommon.Equals("30"))
            {
                return false;
            }

            if (result == null)
            {
                return false;
            }

            bresult = CheckSpecificCharacter(result, GetSpeicficResult, CheckspecificResult); 
            
            if (bresult)
            {
                System.Console.WriteLine("VerfityN0100");
            }

            return bresult;
        }

        private   string GetSpeicficResult(string colResult)
        {
            var splitResult = new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult);
            return splitResult.GetName();
        }

        protected   bool CheckspecificResult(string result)
        { 

            bool bresult = false;            
            if (!String.IsNullOrEmpty(result))
            {
                if (InDataList)
                {
                    bresult = DataList.Any(item => item.array.Any(result.Contains));
                }
                else
                {
                    bresult = DataList.Any(item => item.array.Any(s => !result.Contains(s)));
                }
            }
            return bresult;
        }
    }
}
